{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>分类列表</h5>
        </div>
        <div class="ibox-content">
            <!--搜索框开始-->           
            <div class="row">
                <div class="col-sm-12">   
                <div  class="col-sm-2" style="width: 100px">
                    <div class="input-group" >  
                        <a href="{:url('add_cate')}"><button class="btn btn-outline btn-primary" type="button">添加分类</button></a> 
                    </div>
                </div>                                                                    
                </div>
            </div>
            <!--搜索框结束-->
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="table table-bordered table-hover">
                        <thead>
                            <tr class="long-tr">
                                <th>ID</th>
                                <th>名称</th>
                                <th>排序</th>
                                <th>状态</th>
                                <!--<th width="15%">添加时间</th>-->
                                <!--<th width="15%">更新时间</th>-->
                                <th width="20%">操作</th>
                            </tr>
                        </thead>
                        <tbody id="article_list">
                            {foreach name="list" item="vo"}
                                <tr class="long-td">
                                    <td>{$vo.id}</td>
                                    <td style="text-align: left;padding-left: 100px;">{$vo.name}</td>
                                    <td>{$vo.orderby}</td>                                                              
                                    <td>
                                        {if condition="$vo['status'] == 1"}
                                            <a href="javascript:;" onclick="cate_state({$vo.id});">
                                                <div id="zt{$vo.id}"><span class="label label-info">开启</span></div>
                                            </a>
                                        {else/}    
                                            <a href="javascript:;" onclick="cate_state({$vo.id});">
                                                <div id="zt{$vo.id}"><span class="label label-danger">禁用</span></div>
                                            </a>
                                        {/if}   
                                    </td>
                                    <!--<td>{$vo.create_time}</td>-->
                                    <!--<td>{$vo.update_time}</td>-->
                                    <td>
                                        <a href="{:url('edit_cate',['id'=>$vo.id])}" class="btn btn-primary btn-xs">
                                            <i class="fa fa-paste"></i> 编辑</a>&nbsp;&nbsp;
                                        <!--<a href="javascript:;" onclick="del_cate({$vo.id})" class="btn btn-danger btn-xs">-->
                                            <!--<i class="fa fa-trash-o"></i> 删除</a>   -->
                                    </td>
                                </tr>
                                {foreach name="vo.son" item="vv"}
                                        <tr class="long-td">
                                            <td>{$vv.id}</td>
                                            <td style="text-align: left;padding-left: 120px;">--{$vv.name}</td>
                                            <td>{$vv.orderby}</td>
                                            <td>
                                                {if condition="$vv['status'] == 1"}
                                                <a href="javascript:;" onclick="cate_state({$vv.id});">
                                                    <div id="zt{$vv.id}"><span class="label label-info">开启</span></div>
                                                </a>
                                                {else/}
                                                <a href="javascript:;" onclick="cate_state({$vv.id});">
                                                    <div id="zt{$vv.id}"><span class="label label-danger">禁用</span></div>
                                                </a>
                                                {/if}
                                            </td>
                                            <!--<td>{$vo.create_time}</td>-->
                                            <!--<td>{$vo.update_time}</td>-->
                                            <td>
                                                <a href="{:url('edit_cate',['id'=>$vv.id])}" class="btn btn-primary btn-xs">
                                                    <i class="fa fa-paste"></i> 编辑</a>&nbsp;&nbsp;
                                                <!--<a href="javascript:;" onclick="del_cate({$vo.id})" class="btn btn-danger btn-xs">-->
                                                <!--<i class="fa fa-trash-o"></i> 删除</a>   -->
                                            </td>
                                        </tr>
                                {/foreach}



                            {/foreach}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Panel Other -->
</div>
{include file="public/footer" /}


<script type="text/javascript">

/**
 * [del 删除用户]
 * @Author[田建龙 864491238@qq.com]
 * @param   {[type]}    id [用户id]
 */
function del_cate(id){
    layer.confirm('确认删除此分类?', {icon: 3, title:'提示'}, function(index){
        //do something
        $.getJSON('./del_cate', {'id' : id}, function(res){
            if(res.code == 1){
                layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                    window.location.href="{:url('article/index_cate')}";
                });               
            }else{
                layer.msg(res.msg,{icon:0,time:1500,shade: 0.1});
            }
        });

        layer.close(index);
    })

}

/**
 * [user_state 用户状态]
 * @param  {[type]} val [description]
 * @Author[田建龙 864491238@qq.com]
 */
function cate_state(val){
    $.post('{:url("cate_state")}',
    {id:val},
    function(data){
         
        if(data.code==1){
            var a='<span class="label label-danger">禁用</span>'
            $('#zt'+val).html(a);
            layer.msg(data.msg,{icon:2,time:1500,shade: 0.1,});
            return false;
        }else{
            var b='<span class="label label-info">开启</span>'
            $('#zt'+val).html(b);
            layer.msg(data.msg,{icon:1,time:1500,shade: 0.1,});
            return false;
        }         
        
    });
    return false;
}


</script>
</body>
</html>